package com.xq.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xq.springboot.prop.GirlProp;

/**
 * 入门示例
 * 
 * @author 郭凯强
 */
@RestController
@RequestMapping("/demo")
public class HelloWorldController {
	// 设置属性名称
	@Value("${name}")
	private String name;
	// 设置属性对象 @ConfigurationProperties
	@Autowired
	private GirlProp girlProp;

	@GetMapping("/hello")
	public String hello() {
		return "Hello World!";
	}

	/**
	 * 路径参数测试
	 * @param vname 路径参数的值
	 * @return 路径参数的值
	 */
	@GetMapping("/prop/{vname}")
	public String prop(@PathVariable(required=false,name="vname") String vname) {
		StringBuilder sbBuilder=new StringBuilder(girlProp.getCupSize());
		sbBuilder.append("[name:").append(name).append("]");
		if (vname!=null) {
			sbBuilder.append("[pathVname=").append(vname).append("]");
		}
		return sbBuilder.toString();
	}
}
